Fix Stack::compare ignoring element results for different-sized stacks#8297
Merged
tlively merged 1 commit intoWebAssembly:mainfrom Feb 11, 2026
Merged
Conversation
When comparing stacks of different sizes, the compare function iterated from the top matching elements pairwise, accumulating a comparison result. However, when one stack was exhausted, it returned LESS or GREATER based solely on which stack was taller, ignoring any contradicting result from the element comparisons. For example, with Stack<Bool> comparing [true, false] against [true]: the top elements give false < true (LESS), but the first stack is taller, so the code returned GREATER. The correct answer is NO_RELATION since the element ordering conflicts with the size ordering. The fix checks the accumulated result before returning at the size-difference branches, returning NO_RELATION when there is a conflict.
tlively
approved these changes
Feb 11, 2026
Member
tlively
left a comment
There was a problem hiding this comment.
Thanks! Out of curiosity, how are you finding all these bugs? Are you using all these APIs for something?
Contributor
Author
|
I am implementing a testing technique for this. I might report more issues soon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When comparing stacks of different sizes,
Stack::compareiterated from the top matching elements pairwise, accumulating a comparison result. However, when one stack was exhausted, it returnedLESSorGREATERbased solely on which stack was taller, ignoring any contradicting result from the element-wise comparisons.For example, with
Stack<Bool>comparing[true, false]against[true]:falsevstrue→LESSbis exhausted,ahas extra non-bottom elements → code returnedGREATERNO_RELATION(the element ordering conflicts with the size ordering)The fix checks the accumulated
resultbefore returning at the size-difference branches, returningNO_RELATIONwhen there is a conflict.Note: This bug was not caught by the lattice fuzzer because
Stackis not included in the fuzz variants inwasm-fuzz-lattices.cpp.Test plan
StackLattice.CompareDifferentSizeConflicttest case